<?php

namespace Acme\PinnwandBundle\Entity;

use Symfony\Component\HttpFoundation\Request;
use Acme\PinnwandBundle\Entity\Pinnwandimage;

class Pinnwandgalerie {
	private $id;
	private $path;
	private $apath;
	private $base_url;
	private $images = array ();
	
	/**
	 * Constructor
	 */
	public function __construct($path) {
		$arr_path = explode ( '/', trim ( $path ["path"] ) );
		foreach ( $arr_path as $key => $data ) {
			if ($key == 3) {
				$this->id = $data;
			}
		}
		$this->base_url = $path ["base_url"];
		$this->path = $path ["path"];
		$this->apath = $path ['apath'];
		$this->setImages ();
	}
	public function getId() {
		return $this->id;
	}
	private function getPath() {
		return $this->path;
	}
	private function getAPath() {
		return $this->apath;
	}
	private function getBaseUrl() {
		return $this->base_url;
	}
	private function setImages() {
		$arr_data = array ();
		if ($handle = opendir ( $this->getAPath () . $this->getPath () )) {
			while ( false !== ($file = readdir ( $handle )) ) {
				if (! is_dir ( $this->getAPath () . $this->getPath () . $file ) && $file != "." && $file != ".." && $file != ".htaccess") {
					$arr_data ["base_url"] = $this->getBaseUrl ();
					$arr_data ["path"] = $this->getPath ();
					$arr_data ["file"] = $file;
					$this->images [] = new Pinnwandimage ( $arr_data );
				}
			}
		}
	}
	public function getImages() {
		return $this->images;
	}
	public function isGalerie() {
		if (count ( $this->images ) > 0) {
			return true;
		} else {
			return false;
		}
	}
}